/**
 * \file
 *           tlmRmtCfgDataInfoCon.cpp
 * \brief
 *           Implements tlmRmtCfgDataInfoCon class for Telematics services
 *           this is the class of data infomation of connection message for remote configuration.
 *
 * \par Author (last changes):
 *          - Zeng Jie
 *          - BUIC, Continental Automotive Holdings Co., Ltd.
 * \par Project Leader:
 *          -
 * \par Responsible Developer:
 *          - Zeng Jie
 *          - BUIC, Continental Automotive Holdings Co., Ltd.
 * \par Responsible Architect:
 *          - Zhang Fa
 *          - BUIC, Continental Automotive Holdings Co., Ltd.
 *
 * \par Project:
 *      DPCA2
 *
 * \par SW-Component:
 *      Telematics
 *
 * \par SW-Package:
 *      Telematics
 *
 * \par SW-Module:
 *      Telematics Application
 *
 * \par SW-Architecture Specification:
 *      DPCA2_TELEMATICS_SW_DD_07a_ready.doc
 *
* \par SW-Design Specification:
 *      DPCA2_TLM-RMTCFG_SW_DD_01d_released.doc
 *
 * \par SW-Test Case Specification:
 *
 * \par CM-Info:
 *
 * \note
 *      This is a note.
 *
 * \bug
 *      - there are no known bugs
 *
 * \par Module-History:
 *
 * \verbatim
 * Date                Author					Reason
 * 10 Dec 2013        Zeng Jie              Initial Creation
 * The latest entry at the head of the history list.
 * \endverbatim
 *
 * \par Copyright Notice:
 * Copyright (C) 2012 Continental Automotive Holdings Co., Ltd.
 * Alle Rechte vorbehalten. All Rights Reserved.\n
 * The reproduction, transmission or use of this document or its contents is
 * not permitted without express written authority.\n
 * Offenders will be liable for damages. All rights, including rights created
 * by patent grant or registration of a utility model or design, are reserved.
 *
 */

#include "stdafx.h"
#include <stdlib.h>
#include "tlmRmtCfgDataInfoCon.h"
#include "string.h"
/**
* \brief tlmRmtCfgDataInfoCon: this is constructor of tlmRmtCfgDataInfoCon class
*
* \note
*
* \param[in]
* - bufptr: pointer to buffer that store the datainfo message
*   size  : size of the datainfo buffer
*
* \return
* - none
*/
tlmRmtCfgDataInfoCon::tlmRmtCfgDataInfoCon(uint8_t* bufPtr, uint32_t size) : tlmRmtCfgDataInfo(bufPtr, size), mLanguage(0) { /*DG CPP2ISQP-ISQPcpp Rule 8.4.8-SCC_GRANT_0013*/
    //#[ operation tlmRmtCfgDataInfoCon(uint8_t*,uint32_t)
    //#]
    memset(mSwVer, 0, sizeof(mSwVer));
    memset(mVin, 0, sizeof(mVin));
}

/**
* \brief tlmRmtCfgDataInfoCon: this is default constructor of tlmRmtCfgDataInfoCon class
*
* \note
*
* \param[in]
* - none
*
* \return
* - none
*/
tlmRmtCfgDataInfoCon::tlmRmtCfgDataInfoCon() {
}

/**
* \brief ~tlmRmtCfgDataInfoCon: this is destructor of tlmRmtCfgDataInfoCon class 
*
* \note
*
* \param[in]
* - none
*
* \return
* - none
*/
tlmRmtCfgDataInfoCon::~tlmRmtCfgDataInfoCon() {
}

/**
* \brief Fill : fill the data info of connection message.
*               it shall fill vin code, language and sw version
*
* \note
*
* \param[in]
* - none
*
* \return
* - none
*
* [Covers: MRN_TLM-RMTCFG_SW_DD_031]
*/
void tlmRmtCfgDataInfoCon::Fill() {
    //#[ operation Fill()
    //before use Fill(), we must set the dataInfobuffer     
    
    //Init the dataInfo Msg 
    //As code, vin, language, version would not have escape code, we don't process it.  

    
    mDataInfoBuffer.reset();     
    
    //the first byte should be 0x7E
    mDataInfoBuffer.setValue(SEPERATE_LEVEL_1); 
              
              
    //set service vin
    //next is 0x10  
    mDataInfoBuffer.setValue(TLM_RMT_CFG_DATA_INFO_CODE_VIN); 
    mDataInfoBuffer.setData(mVin, TLM_VIN_FULL_LENGTH);  
     
    mDataInfoBuffer.setValue(SEPERATE_LEVEL_1);  
    
    //set language
    //next is 0x13 
    mDataInfoBuffer.setValue(TLM_RMT_CFG_DATA_INFO_CODE_LANGUAGE); 
    
    mDataInfoBuffer.setValue(mLanguage);   
    
    mDataInfoBuffer.setValue(SEPERATE_LEVEL_1);      
    
    
    
    //set SW Version
    //next is 0x14 
    mDataInfoBuffer.setValue(TLM_RMT_CFG_DATA_INFO_CODE_SW_VER); 
    //_itoa_s(mSwVer, reinterpret_cast<char *>(tmpBuf), 10, 10);
    mDataInfoBuffer.setData(mSwVer, TLM_SW_VER_LENGTH);     
    
    
    //set the datainfo size
    mDataInfoSize = mDataInfoBuffer.getSize();
    //#]
}

/**
* \brief GetMaxDataInfoSize: Get the max length of data info of connection message.
*
* \note
*
* \param[in]
* - none
*
* \return
* -  uint32_t : the max data info size
*
*/
uint32_t tlmRmtCfgDataInfoCon::GetMaxDataInfoSize() {
    //#[ operation GetMaxDataInfoSize()
    return  TLM_RMT_CFG_DATA_INFO_CON_MAX_SIZE;
    //#]
}

/**
* \brief Init: Init the data info of connection message, set vin code, language and sw version
*
* \note
*
* \param[in]
* - none
*
* \return
* - none
*
* [Covers: MRN_TLM-RMTCFG_SW_DD_030]
*/
void tlmRmtCfgDataInfoCon::Init() {
    //#[ operation Init()
    char * vin="TestVin0123456789";
    uint8_t language = 10;
    char * swVer = "00.00.00";
    uint8_t * pVin=NIL;
    uint8_t * pSwVer=NIL;
    

    if(mItsService != NIL)
    {
        pVin = mItsService->GetServiceVin();
        language = mItsService->GetLanguage();
        pSwVer = mItsService->GetSwVersion();
    }

    if(pVin != NIL)
    {
        SetVin(pVin,  TLM_SERVICE_VIN_LEN);    
    }
    else
    {
        SetVin(reinterpret_cast<uint8_t *>(vin), strlen(vin));
    }
    
    SetLanguage(language);

    if(pSwVer != NIL)
    {
        SetSwVer(pSwVer, strlen(reinterpret_cast<char *>(pSwVer)));     
    }
    else
    {
        SetSwVer(reinterpret_cast<uint8_t *>(swVer));    
    }
    
    
    //#]
}


/**
* \brief SetStatus: Set the language
*
* \note
*
* \param[in]
* - language: the language shall be set
*
* \return
* - none
*
*/
void tlmRmtCfgDataInfoCon::SetLanguage(uint8_t language) {
    //#[ operation SetLanguage(uint8_t)
    mLanguage = language;
    //#]
}

/**
* \brief SetStatus: Set the sw version
*
* \note
*
* \param[in]
* - swVer: pointer to SW version string
*
* \return
* - none
*
*/
void tlmRmtCfgDataInfoCon::SetSwVer(uint8_t*  swVer) {
    //#[ operation SetSwVer(uint32_t)
                  
    memset(mSwVer, 0, sizeof(mSwVer));  
    memcpy(mSwVer, swVer, TLM_SW_VER_LENGTH);  
    
    mSwVer[TLM_SW_VER_LENGTH]=0;
    //#]
}

/**
* \brief SetStatus: Set the sw version
*
* \note
*
* \param[in]
* - swVer: pointer to SW version string
* - size : size of the SW version string that shall be set
*
* \return
* - none
*
*/
void tlmRmtCfgDataInfoCon::SetSwVer(uint8_t*  swVer, uint32_t size) {
    //#[ operation SetSwVer(uint32_t)
    uint32_t actSize = 0;

    if(size < TLM_SW_VER_LENGTH)
    {
        actSize = size;
    }
    else
    {
        actSize = TLM_SW_VER_LENGTH;
    }
                  
    memset(mSwVer, 0, sizeof(mSwVer));  
    memcpy(mSwVer, swVer, actSize);  
    
    mSwVer[TLM_SW_VER_LENGTH]=0;
    //#]
}

/**
* \brief SetStatus: Set the vin code
*
* \note
*
* \param[in]
* - vin: pointer to vin code buffer
*   size: size of the vin code
*
* \return
* - none
*
*/
void tlmRmtCfgDataInfoCon::SetVin(uint8_t* vin, uint32_t size) {
    //#[ operation SetVin(uint8_t*,uint32_t)
    uint32_t actSize =  TLM_VIN_FULL_LENGTH;
    
    if(size < TLM_VIN_FULL_LENGTH)
    {
    	actSize = size;
    }               
    
    memcpy(mVin, vin, actSize);  
    
    mVin[TLM_VIN_FULL_LENGTH]=0;
    //#]
}
